/* This header can be included only after rendVertAttr.hpp */

#ifndef __vert_attr_H__
#error rendVertAttr.hpp needs to be included first
#endif

#define SETUP_VERTEX_ATTR_POINTERS_MASK_vertex		0x00000001
#define SETUP_VERTEX_ATTR_POINTERS_MASK_normal		0x00000002
#define SETUP_VERTEX_ATTR_POINTERS_MASK_blendw		0x00000004
#define SETUP_VERTEX_ATTR_POINTERS_MASK_tcoord		0x00000008


template < class VERTEX_T >
inline void
setupVertexAttrPointers(
	const rend::ActiveAttrSemantics& active_attr_semantics,
	const uintptr_t va = 0)
{
#if (0 == SETUP_VERTEX_ATTR_POINTERS_MASK) || (SETUP_VERTEX_ATTR_POINTERS_MASK & SETUP_VERTEX_ATTR_POINTERS_MASK_vertex)

	if (active_attr_semantics.semantics_vertex != -1)
	{
		const float (VERTEX_T::* const offs)[3] = &VERTEX_T::pos;

		glVertexAttribPointer(active_attr_semantics.getVertexAttr(), 3, GL_FLOAT, GL_FALSE, sizeof(VERTEX_T),
			*reinterpret_cast< const int8_t* const* >(&offs) + va);
	}

#endif

#if (0 == SETUP_VERTEX_ATTR_POINTERS_MASK) || (SETUP_VERTEX_ATTR_POINTERS_MASK & SETUP_VERTEX_ATTR_POINTERS_MASK_normal)

	if (active_attr_semantics.semantics_normal != -1)
	{
		const float (VERTEX_T::* const offs)[3] = &VERTEX_T::nrm;

		glVertexAttribPointer(active_attr_semantics.getNormalAttr(), 3, GL_FLOAT, GL_FALSE, sizeof(VERTEX_T),
			*reinterpret_cast< const int8_t* const* >(&offs) + va);
	}

#endif

#if (0 == SETUP_VERTEX_ATTR_POINTERS_MASK) || (SETUP_VERTEX_ATTR_POINTERS_MASK & SETUP_VERTEX_ATTR_POINTERS_MASK_blendw)

	if (active_attr_semantics.semantics_blendw != -1)
	{
		const float (VERTEX_T::* const offs)[4] = &VERTEX_T::bon;

		glVertexAttribPointer(active_attr_semantics.getBlendWAttr(), 4, GL_FLOAT, GL_FALSE, sizeof(VERTEX_T),
			*reinterpret_cast< const int8_t* const* >(&offs) + va);
	}

#endif

#if (0 == SETUP_VERTEX_ATTR_POINTERS_MASK) || (SETUP_VERTEX_ATTR_POINTERS_MASK & SETUP_VERTEX_ATTR_POINTERS_MASK_tcoord)

	if (active_attr_semantics.semantics_tcoord != -1)
	{
		const float (VERTEX_T::* const offs)[2] = &VERTEX_T::txc;

		glVertexAttribPointer(active_attr_semantics.getTCoordAttr(), 2, GL_FLOAT, GL_FALSE, sizeof(VERTEX_T),
			*reinterpret_cast< const int8_t* const* >(&offs) + va);
	}

#else

	// When texcoord is expected but the vertex type does not supply the semantics, substitute for pos.xy
	if (active_attr_semantics.semantics_tcoord != -1)
	{
		const float (VERTEX_T::* const offs)[3] = &VERTEX_T::pos;

		glVertexAttribPointer(active_attr_semantics.getTCoordAttr(), 2, GL_FLOAT, GL_FALSE, sizeof(VERTEX_T),
			*reinterpret_cast< const int8_t* const* >(&offs) + va);
	}

#endif
}

